package com.om.common;

import java.util.HashMap;

import org.apache.lucene.document.Field;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;



public class LuceneIndex extends BaseBean {
	
	
	protected HashMap<String, Field.Index>indexTypes= new HashMap<String, Field.Index>();
	protected HashMap<String, Class>queryTypes = new HashMap<String,Class>();
	
	public  String[] special_fields = new String[0];
	public  Field.Index[] special_index = new Field.Index[0];
	public  Class[] special_query_class= new Class[0];
	
	public void init() throws Exception{
		super.init();
		for(int i=0;i<this.special_fields.length;i++){
			String field = this.special_fields[i];
			this.indexTypes.put(field, this.special_index[i]);
			this.queryTypes.put(field, special_query_class[i]);
		}
	}
	
	public boolean containsSpecialField(String field){
		 return indexTypes.containsKey(field);
	}
	
	protected Field.Index getSpecialIndex(String field){
		return this.indexTypes.get(field);
	}
	
	
	
	protected Query getSpecialQuery(String field,Term term){
		Query q = null;
		try{
			Class cls = queryTypes.get(field);
			if(cls!=null){
				q= (Query)cls.getConstructors()[0].newInstance(term);
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return q;
	}
	
	
	
	
/*	protected void init(){
		for(int i=0;i<this.special_fields.length;i++){
			String field = this.special_fields[i];
			this.indexTypes.put(field, this.special_index[i]);
			this.queryTypes.put(field, special_query_class[i]);
		}
	}*/
	
	
}
